<?php
declare (strict_types = 1);

namespace app\api\model;

use think\Model;

/**
 * @mixin \think\Model
 */
class CommissionFlow extends Model
{
    protected $table = 'ea_commission_flow';

    /**
     * @param $master_id
     * @return float|int
     * 累计佣金(已结算+待结算)
     */
    public function waitTotalCommission($master_id)
    {
        $commission = self::where(['master_id'=>$master_id])
            ->where('commission_status','<>',2)
            ->column('get_commission');
        $commission = array_sum($commission);
        return $commission;
    }

    /**
     * @param $master_id
     * @return float|int
     * 累计待结算佣金
     */
    public function yetTotalCommission($master_id)
    {
        $commission = self::where(['master_id'=>$master_id,'commission_status'=>0])
            ->column('get_commission');
        $commission = array_sum($commission);
        return $commission;
    }

    /**
     * @param $master_id
     * @return float|int
     * 累计月佣金(已结算+待结算)
     */
    public function waitMonthCommission($master_id)
    {
        //获取本月开始第一天00:00:00的时间戳
        $start_month = strtotime(date("Y-m-d"));
        //获取下月开始第一天00:00:00的时间戳
        $end_month = strtotime("$start_month +1 month");
        $commission = self::where(['master_id'=>$master_id])
            ->where('commission_status','<>',2)
            ->where('create_time','>=',$start_month)
            ->where('create_time','<',$end_month)
            ->column('get_commission');
        $commission = array_sum($commission);
        return $commission;
    }

    /**
     * @param $master_id
     * @return float|int
     * 累计月佣金(待结算)
     */
    public function yetMonthCommission($master_id)
    {
        //获取本月开始第一天00:00:00的时间戳
        $start_month = strtotime(date("Y-m-d"));
        //获取下月开始第一天00:00:00的时间戳
        $end_month = strtotime("$start_month +1 month");
        $commission = self::where(['master_id'=>$master_id,'commission_status'=>0])
            ->where('create_time','>',$start_month)
            ->where('create_time','<',$end_month)
            ->column('get_commission');
        $commission = array_sum($commission);
        return $commission;
    }
}
